﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Packager
{
    public partial class frmSolutions : Form
    {
        private List<Solution> solutions = new List<Solution>();

        public frmSolutions()
        {
            InitializeComponent();
        }

        public List<Solution> Solutions
        {
            get
            {
                return solutions;
            }
            set
            {
                solutions = value;
            }
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            foreach (Solution sol in solutions)
                ListViewAdd(sol);
        }

        private void tsbAdd_Click(object sender, EventArgs e)
        {
            frmSolution solfrm = new frmSolution();
            if (solfrm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                ListViewAdd(solfrm.Solution);
        }

        private void ListViewAdd(Solution sol)
        {
            ListViewItem lvi = lsvSolutions.Items.Add(sol.SolutionFile);
            lvi.SubItems.Add(sol.SolutionConfig);
        }

        private void tsbRemove_Click(object sender, EventArgs e)
        {
            if (lsvSolutions.SelectedItems.Count > 0)
                lsvSolutions.Items.Remove(lsvSolutions.SelectedItems[0]);
        }

        private void tsbSave_Click(object sender, EventArgs e)
        {
            solutions.Clear();
            foreach (ListViewItem lvi in lsvSolutions.Items)
            {
                string a = lvi.Text;
                string b = lvi.SubItems[1].Text;
                solutions.Add(new Solution() { SolutionFile =  lvi.Text, SolutionConfig =  lvi.SubItems[1].Text });
            }
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }

        private void tsbUndo_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            Close();
        }
    }
}
